//
// Ephi - simulation of magnetic fields and particles
// Copyright (C) 2007 Indrek Mandre <indrek(at)mare.ee>
// For more information please see http://www.mare.ee/indrek/ephi/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "ephi.hpp"

int main (int argc, char *argv[])
{
  {
    Statics statics;
    ElectroDynamics dyn(statics);
    make_solenoid (statics, 5, 0.1, 0.008, 0.05, 5000);
    Screen screen (800, 800, 0.9, 0.9);
    Scene scene(dyn);
    printf ("OK: calculating solenoid\n");
    scene.calc (screen);
    printf ("OK: calc done, rendering bmap\n");
    scene.set_coloring (0, true);
    scene.render_map (screen);
    printf ("OK: rendering lines now..\n");

    scene.calibrate_bline_step (vect3d(0, 0, 0), 0.01);
    scene.render_bline_range (screen, vect3d(0, 0, 0), vect3d(0, 0.093, 0), Screen::BLUE, 0.5, 1.0);
    scene.render_bline_range (screen, vect3d(0, 0, 0), vect3d(0, -0.093, 0), Screen::BLUE, 0.5, 1.0);
    screen.write ("solenoid_lines.bmp");
  }

  {
    Statics statics;
    ElectroDynamics dyn(statics);
    make_polywell_cube (statics, 0.3, 0.02, 0.005, 100000);
    Screen screen (800, 800, 1.5, 1.5);
    Scene scene(dyn);
    printf ("OK: calculating polywell cube\n");
    scene.calc (screen);
    printf ("OK: calc done, rendering bmap\n");
    scene.set_coloring (0, true);
    scene.render_map (screen);
    printf ("OK: rendering lines now..\n");

    scene.calibrate_bline_step (vect3d(-0.3, 0, 0), 0.03);

    scene.render_bline_range (screen, vect3d(-0.3, 0, 0), vect3d(-0.3, 0.22, 0), Screen::BLUE,
        0.5, 2.0, vect3d(-0.265, 0.265, 0), 0.05);
    scene.render_bline_range (screen, vect3d(-0.3, 0, 0), vect3d(-0.3, -0.22, 0), Screen::BLUE,
        0.5, 2.0, vect3d(-0.265, -0.265, 0), 0.05);
    scene.render_bline_range (screen, vect3d(0.3, 0, 0), vect3d(0.3, 0.22, 0), Screen::BLUE,
        0.5, 2.0, vect3d(0.265, 0.265, 0), 0.05);
    scene.render_bline_range (screen, vect3d(0.3, 0, 0), vect3d(0.3, -0.22, 0), Screen::BLUE,
        0.5, 2.0, vect3d(0.265, -0.265, 0), 0.05);

    scene.render_bline_range (screen, vect3d(0, -0.3, 0), vect3d(0.22, -0.3, 0), Screen::BLUE,
        0.5, 2.0, vect3d(0.265, -0.265, 0), 0.05);
    scene.render_bline_range (screen, vect3d(0, -0.3, 0), vect3d(-0.22, -0.3, 0), Screen::BLUE,
        0.5, 2.0, vect3d(-0.265, -0.265, 0), 0.05);
    scene.render_bline_range (screen, vect3d(0, 0.3, 0), vect3d(0.22, 0.3, 0), Screen::BLUE,
        0.5, 2.0, vect3d(0.265, 0.265, 0), 0.05);
    scene.render_bline_range (screen, vect3d(0, 0.3, 0), vect3d(-0.22, 0.3, 0), Screen::BLUE,
        0.5, 2.0, vect3d(-0.265, 0.265, 0), 0.05);

    screen.write ("polywell_cube_lines.bmp");
  }

  return 0;
}

